import plotly

import plotly.offline as py
from plotly.graph_objs import Scatter,Layout
import plotly.graph_objs as go

trace1 = go.Scatter(
    x=[1,2],
    y=[1,2],
)

trace2 = go.Scatter(x=[1,2],
                    y=[2,1]
)

py.plot([trace1,trace2])

trace=go.Scatter(
    x=[1,2,3],
    y=[1,2,3],
    marker=dict(
        color=['red','blue','green'],
        size=[30,80,200],
    ),
    mode='markers+lines'
)

py.plot([trace])

trace1=go.Scatter(
    name="lenged1",
    x=[1,2],
    y=[2,1]
)
trace2=go.Scatter(
    name="lenged2",
    x=[2,1],
    y=[2,1]
)

layout = go.Layout(
    showlegend=True,
    legend=dict(
        x=0.9,
        y=1.1
    )
)

data = [trace1,trace2]
fig = go.Figure(data=data,layout=layout)
py.plot(fig)

trace1 = go.Scatter(
    x=[1,2,3],
    y=[1,2,3],
    text = ['A','B','C'],
    textposition = 'top center',
    mode='markers+text',
    marker=dict(
        size=[20,20,20]
    )
)

data=[trace1]
py.plot(data)

##设置坐标轴

trace = go.Scatter(
    x=[1,2,3,4],
    y=[1,2,3,6]
)

axis_template = dict(
    showgrid=True,#网格
    zeroline=True,#显示基线,即画出x轴，y轴
    nticks=20,
    showline=True,
    title='X axis',
    mirror='all',
    zerolinecolor='#FF0000'
)

layout = go.Layout(
    xaxis = axis_template,
    yaxis = axis_template
)

data = [trace]

fig=go.Figure(
    data=data,
    layout=layout
)
py.plot(fig)

# 热力图
trace = go.Heatmap(
    z=[
        [1,2,3,4],
        [5,6,7,8]
    ]
)

data = [trace]
py.plot(data)

# 柱状图

trace = go.Bar(
    x=[1,2],
    y=[1,2],
    marker = dict(
        color=['#FF0000','#00FF00'],
    )

)

data = [trace]
py.plot(data)

## 填充区域

trace = go.Scatter(
    x=[1,2,6],
    y=[1,2,0.5],
    fill='tonexty',
    fillcolor='#FF0'
)

data = [trace]
py.plot(data)

# 直方图

trace = go.Histogram(
    x=[1,2,3,3,3,4,5],
    marker=dict(
        color=['#F0F','#FF0','#0FF']
    )
)
data = [trace]
py.plot(data)

# 画地图

trace = go.Scattergeo(
    lon=[100,400],
    lat=[0,0],
    marker=dict(
        color=['red','blue'],
        size=[30,50]
    ),
    mode='markers'
)

data=[trace]
py.plot(data)

# 3D表面图

trace = go.Surface(
    colorscale='Viridis',
    z=[
        [300,5,8,13],
        [2,3,8,5]
    ]
)

data =[trace]
py.plot(data)

# 箱线图

trace = go.Box(
    x=[1,2,3,3,3,4,5]
)

data = [trace]
py.plot(data)

## 地理热度图

trace = go.Choropleth(
    locations=['AZ','CA','VT'],
    locationmode='USA-states',
    colorscale='Viridis',
    z=[10,20,40]
)

layout=dict(
    geo=dict(scope='usa')
)

data = [trace]
map = go.Figure(data=data, layout=layout)
py.plot(map)

# 3D点图

trace = go.Scatter3d(
    x=[9,8,5,1],
    y=[1,2,4,8],
    z=[11,8,15,3],
    mode='lines'
)

data = [trace]
py.plot(data)

# 2D 直方热力图

trace  =go.Histogram2d(
    x=[1,2,3,3,3,4,5],
    y=[1,2,3,3,3,4,5]
)

data = [trace]
py.plot(data)